package com.cszjzx.member.action;


import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.cszjzx.member.po.Department;
import com.cszjzx.member.po.Major;
import com.cszjzx.member.service.DepartmentService;
import com.cszjzx.member.service.DepartmentServiceImpl;
import com.cszjzx.member.service.MajorService;
import com.cszjzx.member.service.MajorServiceImpl;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class ManagementOfDepartmentAndClassAction extends ActionSupport {
	
	
	private String departmentName;
	private int departmentId;
	private String majorName;
	private String message;
	private int majorId;
	
	DepartmentService departmentservice = new DepartmentServiceImpl();
	MajorService majorservice = new MajorServiceImpl();
	HttpServletRequest request  = ServletActionContext.getRequest();
	List<Department> departments;
	
	
	
	
	public int getMajorId() {
		return majorId;
	}
	public void setMajorId(int majorId) {
		this.majorId = majorId;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public List<Department> getDepartments() {
		return departments;
	}
	public void setDepartments(List<Department> departments) {
		this.departments = departments;
	}
	public String getMajorName() {
		return majorName;
	}
	public void setMajorName(String majorName) {
		this.majorName = majorName;
	}
	public int getDepartmentId() {
		return departmentId;
	}
	public void setDepartmentId(int departmentId) {
		this.departmentId = departmentId;
	}
	public String getDepartmentName() {
		return departmentName;
	}
	public void setDepartmentName(String departmentName) {
		this.departmentName = departmentName;
	}
	
	
	
	
	/**
	 * 获取数据：无
	 * 作用：获得所有系的列表 
	 * 转出页面：superAdmin/managementOfDepartment.jsp
	 * 提供数据：系列表
	 * @return
	 * @throws Exception
	 */
	public String departmentShow() throws Exception{
		departments = departmentservice.getDepartments();
		return "departmentShow" ;
	}
	
	/**
	 * 获取数据：DepartmentName
	 * 作用：添加一个系
	 * 转出页面：添加成功页面？？？？
	 * 提供数据：成功或错误信息
	 * @return
	 * @throws Exception
	 */
	public String addDepartment() throws Exception{
		
		if(departmentservice.addDepartment(departmentName)==true){
			message = "添加系"+departmentName+"成功";
		}else{
			message = "添加系"+departmentName+"失败";
		}
		return "addDepartment";
		
	}
	
	/**
	 * 获取数据：departmentId
	 * 作用：获得特定系的班级列表
	 * 转出页面：superAdmin/managementOfMajor.jsp
	 * 提供数据：系名+班级列表
	 * @return
	 * @throws Exception
	 */
	public String majorShow() throws Exception{
		
		List<Major> majors = majorservice.getMajorsByDepartmentId(departmentId);
		request.setAttribute("majors", majors);
		
		return "majorShow";
	}

	/**
	 * 进入添加班级页面
	 * @return
	 */
	public String showAddMajor(){
		System.out.println("departmentId:"+departmentId);
		return "showAddMajorSuccess";
	}
	/**
	 * 获取数据：Major对象，departmentId
	 * 作用：添加一个班级到一个特定的系
	 * 转出页面：添加成功界面？？？？？？？
	 * 提供数据：无
	 * @return
	 * @throws Exception
	 */
	public String addMajor() throws Exception{
		
		if(majorservice.addMajor(majorName, departmentId)==true){
			message = "添加班级"+majorName+"成功";
		}else{
			message = "添加班级"+majorName+"失败";
		}
		return "addMajor";
	}
	
	/**？？？？？？？
	 * 获取数据：departmentId[]列表							departmentId为设置的value/name值,不行只能用departmentName[]
	 * 作用：删除一个系以及该系下的所有班级   转到删除成功界面
	 * 转出：删除成功确认界面？？？？？？？
	 * 提供数据：无
	 * @return
	 * @throws Exception
	 */
	public String deleteDepartment() throws Exception{
		
		if(departmentservice.deleteDepartments(departmentId)==true){
			message = "删除系成功";
		}else{
			message = "删除系失败";
		}
		return "deleteDepartment";
	}
	
	/**
	 * 获取数据：major[] 									与department同样
	 * 作用：删除一个班级    转到删除成功界面
	 * 转出：删除成功确认界面？？？？？？？
	 * 提供数据：无
	 * @return
	 * @throws Exception
	 */
	public String deleteMajor() throws Exception{
		
		if(majorservice.deleteMajors(majorId)==true){
			message = "删除班级成功";
		}else{
			message = "删除班级失败";
		}
		return "deleteMajor";
	}
	
}
